package vn.fithou.hou_elearning.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import vn.fithou.hou_elearning.R;
import vn.fithou.hou_elearning.activity.DanhsachBaihocActivity;
import vn.fithou.hou_elearning.activity.DanhsachKhoahocActivity;
import vn.fithou.hou_elearning.activity.DanhsachSlideActivity;
import vn.fithou.hou_elearning.util.ImageLoader;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SlideAdapter extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> arrlData;
    private static LayoutInflater inflater = null;
    public ImageLoader imageLoader; 
    
    public SlideAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        arrlData = d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader = new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return arrlData.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.row_khoahoc, null);

        TextView course_name = (TextView)vi.findViewById(R.id.course_name); // tên bài học
        TextView course_title = (TextView)vi.findViewById(R.id.course_title); // ghi chú bài học
        TextView course_count = (TextView)vi.findViewById(R.id.course_count); // 
        ImageView thumb_image = (ImageView)vi.findViewById(R.id.list_image); // ảnh minh họa
        
        HashMap<String, String> hmSlidie = new HashMap<String, String>();
        hmSlidie = arrlData.get(position);
        
        // Setting all values in listview
        course_name.setText(hmSlidie.get(DanhsachSlideActivity.KEY_NAME));
        course_title.setText(hmSlidie.get(DanhsachSlideActivity.KEY_TITLE));
        course_count.setText("");
        thumb_image.setImageResource(R.drawable.slide);
        return vi;
    }
}